package com.ruoyi.system.util;

import org.jfree.chart.*;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RefineryUtilities;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

import java.io.File;
import java.io.IOException;

public class LineChart extends ApplicationFrame {
    private static final String outFilePath ="D:/out_picture.png";
    private static final int width = 900;
    private static final int height = 400;

    public LineChart(String title) {
        super(title);
    }


    //在主函数中执行
    public static void main( String[ ] args ) throws IOException {
        DefaultCategoryDataset dataset = new DefaultCategoryDataset( );
        dataset.addValue( 15 , "schools" , "1970" );
        dataset.addValue( 30 , "schools" , "1980" );
        dataset.addValue( 60 , "schools" ,  "1990" );
        dataset.addValue( 120 , "schools" , "2000" );
        dataset.addValue( 240 , "schools" , "2010" );
        dataset.addValue( 300 , "schools" , "2014" );
        JFreeChart chart = ChartFactory.createLineChart(
                "Years vs School",
                "year",
                "number",
                dataset,
                PlotOrientation.VERTICAL,
                true, true, false);
        ChartFrame chartFrame = new ChartFrame("Test", chart);
        chartFrame.pack();
        ChartUtilities.saveChartAsPNG(new File(outFilePath), chart, width, height);
    }
}
